package com.trendytech.tds.message.dao.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.trendytech.tds.entity.SystemAlertEntity;
import com.trendytech.tds.entity.SystemAlertVO;
import com.trendytech.tds.message.dao.ISystemAlertDAO;

import hm.base.dao.impl.AbstractDAO;

@Repository
public class SystemAlertDAOImpl extends AbstractDAO<SystemAlertEntity> implements ISystemAlertDAO {

	private static final String MAPPER_SELECT_VALUES_BY_IP = "selectValuesByIp";
	private static final String MAPPER_SELECT_VALUES_BY_IP_AND_TYPE = "selectValuesByIpAndType";
	private static final String MAPPER_SELECT_VALUES = "selectValues";
	private static final String MAPPER_SELECT_COUNTER = "selectCounterWithStatusEqual0";
	private static final String MAPPER_SELECT_CONTENT_BY_TYPE ="selectContentByType";
	private static final String MAPPER_SELECT_TYPE_AND_CREATE_TIME ="selectTypeAndCreateTime";
	private static final String MAPPER_SELECT_TYPE_IMPORTANCE ="getImportanceCount";
	private static final String MAPPER_DELETE_LIST = "deletelist";
	@Override
	public List<SystemAlertEntity> getItemValuesByIp(String ip) {
		return sqlSession.selectList(getMapperId(MAPPER_SELECT_VALUES_BY_IP), ip);
	}

	@Override
	public List<SystemAlertEntity> getItemValuesByIpAndType(SystemAlertEntity entity) {
		return sqlSession.selectList(MAPPER_SELECT_VALUES_BY_IP_AND_TYPE, entity);
	}

	@Override
	public List<SystemAlertEntity> getItemValues() {
		// TODO Auto-generated method stub
		return sqlSession.selectList(MAPPER_SELECT_VALUES);
	}

	@Override
	public int getCounet() {
		return sqlSession.selectOne(getMapperId(MAPPER_SELECT_COUNTER));
	}
	
	@Override
	public List<SystemAlertVO> getCounetAndType() {
		return sqlSession.selectList(getMapperId(MAPPER_SELECT_TYPE_AND_CREATE_TIME));
	}

	@Override
	public List<SystemAlertVO> getAlarmCountByType(int type) {
		List<SystemAlertVO> list=sqlSession.selectList(MAPPER_SELECT_CONTENT_BY_TYPE, type);
		return list!=null?list:null;
	}

	@Override
	public List<Integer> getImportanceCount() {
		List<Integer> list=sqlSession.selectList(MAPPER_SELECT_TYPE_IMPORTANCE);
		return list;
	}

	@Override
	public int deleteList(String[] ids) {
		Map<String, String[]> map = new HashMap<String, String[]>();
		map.put("id", ids);
		return sqlSession.delete(getMapperId(MAPPER_DELETE_LIST),map);
	}
}